package com.gang.ssm.bos.system.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.gang.crm.bean.Customer;
import com.gang.ssm.bos.core.anotation.Permission;
import com.gang.ssm.bos.core.toolbox.ajax.AjaxResult;
import com.gang.ssm.bos.system.bean.Noticebill;
import com.gang.ssm.bos.system.service.CustomerService;
import com.gang.ssm.bos.system.service.NoticebillService;

@RequestMapping("/noticebill")
@Controller
public class NoticebillController extends BosController{
	
	@Autowired
	private CustomerService customerService;
	
	@Autowired
	private NoticebillService noticebillService;
	
	@Permission({ADMIN})
	@ResponseBody
	@RequestMapping("/add")
	public AjaxResult add(Noticebill noticebill, Integer decidedzoneId) {
		try {
			noticebillService.save(noticebill, decidedzoneId);
			return success("添加成功!");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return fail("添加失败!");
	}
	
	@ResponseBody
	@RequestMapping("/findCustomerByTelephone")
	public AjaxResult findCustomerByTelephone(String telephone) {
		Customer customer = customerService.findCustomerByTelephone(telephone);
		if(customer != null) {
			return success();
		}
		return fail();
	}
	
	@RequestMapping("/findNoAssociations")
	public String findnoassociations(Map<String,Object> map) {
		List<Noticebill> noticebills = noticebillService.findnoassociations();
		map.put("noticebillList", noticebills);
		return "system/qupai/noAssociationList";
	}
	
	@ResponseBody
	@RequestMapping("/diaodu")
	public AjaxResult edit(@RequestParam("id")Integer id,
			@RequestParam("staffId")Integer staffId) {
		try {
			noticebillService.editStaffId(id,staffId);
			return success("调度成功!");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return fail("调度失败!");
	}

}
